package com.hsylient.javase.chapter11.threadlocal;

import com.hsylient.javase.common.enmu.Status;
import lombok.Data;
import lombok.NoArgsConstructor;

public class ThreadLocalTest {

    private static final ThreadLocal<Employee> USER_INFO = new ThreadLocal<>();

    public static void main(String[] args) {

        Thread hsylient = new Thread(() -> {
            Employee employee = new Employee();
            employee.setName("hsylient");
            USER_INFO.set(employee);
            System.out.println(Thread.currentThread().getName() + "线程获得变量：" + USER_INFO.get());
        });
        hsylient.setName("hsylient");

        Thread ht = new Thread(() -> {
            Employee employee = new Employee();
            employee.setName("ht");
            USER_INFO.set(employee);
            System.out.println(Thread.currentThread().getName() + "线程获得变量：" + USER_INFO.get());
        });
        ht.setName("ht");

        ht.start();
        hsylient.start();
    }

    @Data
    @NoArgsConstructor
    private static class Employee {

        private Long id;

        private String name;

        private Integer age;

        private Double salary;

        private Status status;
    }
}
